package com.derekandbritt.booST.data;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class User {

	@PrimaryKey
	public String userID;
	
	public boolean online;
	public Date lastActivity;
	
	@NotPersistent
	public EnergyLevel currentEnergy;
	
	@NotPersistent
    public List<EnergyLevel> pastEnergy;
	
	@NotPersistent
	public EmotionLevel currentEmotion;
	
	@NotPersistent
	public List<Challenge> activeChallenges;

    @NotPersistent
    public UserStats statistics;
	
	@NotPersistent
    public int flags;
	
	public static final int INCLUDE_ENERGY_FLAG		= 1 << 0;
	public static final int INCLUDE_EMOTION_FLAG 	= 1 << 1;
	public static final int INCLUDE_CHALLENGE_FLAG 	= 1 << 2;
	public static final int INCLUDE_STATISTICS_FLAG = 1 << 3;
	public static final int CREATE_IF_NEEDED_FLAG 	= 1 << 4;
	public static final int IGNORE_CACHE_FLAG       = 1 << 5;
	
	public boolean isOnline() {
	    if(!online || lastActivity == null)
	        return false;
	    
	    long comparableTime = System.currentTimeMillis() - 900000; // -15 min
	    return lastActivity.after(new Date(comparableTime));
	}
	
	public void setOnline(boolean online) {
	    this.online = online;
	}
	
	public void setLastActivity(Date lastActivity) {
	    this.lastActivity = lastActivity;
	}
}
